﻿using System;
using System.IO;
using System.Data;
using MySql.Data.MySqlClient;

//Module : Employee Management
class Emp_mgmt
{


    static void Main(string[] args)
    {
        // Create a MySql Connection with a query 
        bool sucess = false;
        string retValue,uprod_id;

        try
        {

            System.Console.WriteLine(" --------------Employee  Management System  ------------------\n");
            System.Console.WriteLine("Please enter one of the following numeric options\n");
            System.Console.WriteLine("1.Add a Employee");
            System.Console.WriteLine("2.Delete a Employee");
            System.Console.WriteLine("3.Edit a Employee \n");
            System.Console.WriteLine("4. Exit \n");
            // Retrieve the user's choice
            string userChoice = Console.ReadLine();

            System.Console.WriteLine("You entered {0}", userChoice);



            //Switch (Case statement)

            if (userChoice == "1")
            {
                System.Console.WriteLine("Add Emp Id , date of Ownership, Product Id of new Employee");
                System.Console.WriteLine("Enter Employee Id");

                int  uemp_id = Convert.ToInt16(Console.ReadLine());

                System.Console.WriteLine("Enter Date of ownerShip");

                string  udate = Console.ReadLine();

                System.Console.WriteLine("Enter Product Id");

                uprod_id = Console.ReadLine();



                System.Console.WriteLine("You entered following values:");
                System.Console.WriteLine("EmpId :" + uemp_id + " Date:" + udate + " Prod Id:" + uprod_id);


                //create a MySQL connection with a query string
                MySqlConnection connection = new MySqlConnection("server=localhost;database=epoms;uid=root");
                Console.WriteLine("Server Connected");


                connection.Open();
                sucess = true;

                string Query =  string.Format("insert into emp_mgmt(emp_id,own_prod,prod_id) values  ({0},{1},{2} )",uemp_id,udate,uprod_id);
                
                MySqlCommand cmd = new MySqlCommand(Query, connection);

                Console.WriteLine(cmd.CommandText);


                cmd.ExecuteNonQuery();

                MySqlDataReader myReader = cmd.ExecuteReader();

                while (myReader.Read() != false)
                {

                    retValue = myReader.GetString(1);
                    Console.WriteLine(retValue);

                }

                myReader.Close();


            }

        }
        catch (Exception excp)
        {
            Exception myExcp = new Exception("Error connecting you to " +
                     "the my sql server. Error: " + excp.Message, excp);
            throw myExcp;

        }

          
            if (sucess)
            {
                Console.WriteLine("Successful Connection !!!");

            }
        }

    }

